<template>
  <div class="card">
    <!-- 搜索 -->
    <reportSearch :key="levelType" @search="search"></reportSearch>

    <!-- 卡片 -->
    <reportCard :card-data="cardData" @changePage="changePage" @jumpList="jumpList"></reportCard>
  </div>
</template>

<script>
import reportSearch from '@/components/search/reportSearch'
import reportCard from '../reportManage/modules/reportCard.vue'
import { getReportCheckList } from '@/api/report'

export default {
  name: 'card',
  components: {
    reportSearch,
    reportCard
  },
  data () {
    return {
      searchFrom: {
        name: '',
        reportIndexs: '',
        year: '',
        pageIndex: 1,
        pageSize: 10
      },
      // 层级：学校层，专业层，课程层，教师层，学生层
      levelType: '',
      cardData: {}
    }
  },
  created () {
    this.levelType = this.$route.params.type
    this.searchFrom.reportIndexs = this.levelType
    this.getList()
  },
  methods: {
    // 搜索
    search (searchFrom) {
      this.searchFrom.pageIndex = 1
      this.searchFrom.name = searchFrom.name
      this.searchFrom.year = searchFrom.year
      this.getList()
    },
    // 获取card数据
    getList () {
      getReportCheckList(this.searchFrom)
        .then(res => {
          this.cardData = res
        })
        .catch(() => {})
    },
    // 跳转至详情
    jumpList (card) {
      const name = card.reportName
      this.$router.push({
        path: `/report/reportCheck/cardDetail/${this.levelType}`,
        query: {
          id: card.id,
          title: `${name}`,
          standardId: card.targetStandardId
        }
      })
    },
    // 切换分页
    changePage (searchForm) {
      this.searchFrom.pageIndex = searchForm.pageIndex
      this.searchFrom.pageSize = searchForm.pageSize
      this.getList()
    }
  },
  watch: {
    $route (to, from) {
      this.levelType = to.params.type
      this.searchFrom.reportIndexs = this.levelType
      this.getList()
    }
  }
}
</script>

<style scoped>
</style>
